package com.interview.score.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;


@Component
public class RedisKeyUtils {
    private String examRoomCode;
    private String examRoomId;
    private String groupId;
    private String connectLine="-";
    @Autowired
    private Environment environment;
    //获取考场Id中的考场号
    public synchronized String getExamRoomCodeFromExamRoomId(String examRoomId) {
        return StringUtils.getDigits(examRoomId);
    }
    //获取考场Id中的面试组号
    public synchronized String getGroupIdFromExamRoomId(String examRoomId) {
        StringBuilder letters = new StringBuilder();

        for (int i = 0; i < examRoomId.length(); i++) {
            char c = examRoomId.charAt(i);
            if (Character.isLetter(c)) {
                letters.append(c);
            }
        }
        return letters.toString();
    }
    //拼接Redis中的key
    public synchronized String spliceThreeRedisKey(String keyName,String id1,String id2) {
        return environment.getProperty(keyName)+this.connectLine+id1+this.connectLine+id2;
    }

    public synchronized String spliceTwoRedisKey(String keyName,String id) {
        return environment.getProperty(keyName)+this.connectLine+id;
    }
}
